<? include 'page/__header.php'; ?>

<div id="dvLoginContainer" class="shadowMe">
	
    <input type="hidden" id="secret" value="<?=rand(10000000, 99999990);?><?=rand(10000000, 99999990);?><?=rand(10000000, 99999990);?>" />
    
    <input id="txtUsername" type="text" placeholder="" style="float: left;" disabled="true" value="<?=rand(10000000, 99999990);?>"/>
    <input id="txtPassword" type="password" placeholder="Password"  style="float: right;"/>
    
	<div id="btnLogin"></div>
	<div id="dvLoginErrorMessage" class="hideMe"></div>
		
</div>
<script language="JavaScript" type="text/javascript">
	
	$(document).ready(function(){
		$("#txtUsername").focus();
		
		$("#btnLogin").hover(function(){
            $(this).css("background-image", "url('<?=$sys['host']?>/img/youtube_active.png')"); 
        }, function(){
            $(this).css("background-image", "url('<?=$sys['host']?>/img/youtube_dark.png')");
		}).mousedown(function(){
            $(this).css("top","-2px");          
        }).mouseup(function(){
            $(this).css("top","-3px");          
        }).mouseleave(function(){
            $(this).css("top","-3px");
		}).click(function(){
			do__login();
		});
		
		$("#txtUsername, #txtPassword").keydown(function(){
            $("#dvLoginErrorMessage").fadeOut();
        });
		
		pageHeight = Math.round($(document).height() / 2) - 40;     
        $("#dvLoginContainer").css("top", pageHeight + "px");
		
		<?    
            if(doInstall()){
        ?>
    		$("#dvLoginErrorMessage").text("Install completed.");
            $("#dvLoginErrorMessage").fadeIn();
		<?
            }
        ?>
	});
	
	$('input').keypress(function(e){
		if(e.which == 13){			
			do__login();			
			return false;
		}
	});	
	
	function do__login() {
		$("#dvLoginErrorMessage").fadeOut();
		
		var url = "<?=getPage('doinstall')?>";		
		
        data = {
            "secret" : $("#secret").val(),
            "u" : $("#txtUsername").val(),
            "p" : $("#txtPassword").val()
        };
        
        console.log(url);
        
        $.post(url, data, function(json) { 
            
            console.log(json);
                     
            if(json.result && json.result == 1){
                window.setTimeout("location.reload(true)", 300);                
            } else {
                $("#dvLoginErrorMessage").text("Wrong username/password.");
                $("#dvLoginErrorMessage").fadeIn();
            }
        }, "json");
		
	}


</script>
<? include 'page/__footer.php'; ?>